<?php
/**
 * Created by PhpStorm.
 * User: keke
 * Date: 2020/8/15
 * Time: 11:56
 */
namespace App\Model;

use Illuminate\Support\Facades\DB;

class FinanceRoomSupportSetting extends BaseModel
{
    protected $table = 'finance_room_support_setting';
    protected $fields = ['finance_room_support_setting.id', 'room.room_uid', 'room.name', 'finance_room_support_setting.created_at', 'finance_room_support_setting.updated_at'];

    public function getRoomSupportList($request, $supportId)
    {
        $limit = $request->input('limit', 10);
        $page = $request->input('page', 1);
        $roomName = trim($request->input('room_name'));

        $roomUid = $request->input('room_uid');
        $where = !$roomUid ? [] : ['room.room_uid' => $roomUid];


        return DB::connection($this->connection)->table('finance_room_support_setting')
            ->leftJoin('room', 'finance_room_support_setting.room_id',
                '=', 'room.room_id')
            ->where('finance_room_support_setting.support_id', '=', "{$supportId}")
            ->where('room.name', 'like', "%{$roomName}%")
            ->where($where)
            ->orderBy('finance_room_support_setting.id','desc')
            ->paginate($limit,$this->fields,'page',$page);
    }


    public function createRoomSupportRule($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/finance/settle/createRoomSupport', $data, 'urlencoded', 'POST');
    }


    public function updateRoomSupportRule($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/finance/settle/updateRoomSupport', $data, 'urlencoded', 'POST');
    }


    public function deleteRoomSupportSetting($data)
    {
        return curl_request(getKkaudioApiUrl() . '/inner/finance/settle/deleteRoomSupport', $data, 'urlencoded', 'POST');
    }
}
